package org.linys.util;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.linys.model.system.Operator;
import org.springframework.stereotype.Component;

@Component
public class OperateUtil{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -2010005134326352775L;
	public static final String SESSION_SALE_OPERATETIME = "sale_operatetime";
	
	/**
	 * operate_session
	 * 获取用户信息
	 * @return
	 */
	public  Operator getOperator(){
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		Operator operator = (Operator)session.getAttribute("operator_session");
		return operator;
	}
	
	/**
	 * 获取模块的临时表的操作时间
	 * 
	 * @param operatetimeStr
	 * @return
	 */
	public  Date getModelOperateTime(String operatetimeStr){		
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		return (Date)session.getAttribute(operatetimeStr);
	}
	
	/**
	 * 设置模块的操作时间放在session里面
	 * 打开编辑页面的时候就要set
	 * 比如订单模块的session.setAttribute("sale_operatetime",date);
	 */
	public  void setModelOperateTime(String operatetimeStr,Date date){
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		session.setAttribute(operatetimeStr, date);		
	}


}
